﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataAccess;
namespace QLDSVCNTT_Nhom1
{
    public partial class frmQuanLyPCGD : Form
    {
        public frmQuanLyPCGD()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (lvPCGD.SelectedItems.Count >0)
            {
                PhanCongGiangDay pc = new PhanCongGiangDay();
                GetPCGD(pc);
                if (PhanCongGiangDay.Delete(pc) > 0 )
                {
                    MessageBox.Show("Xóa thành công", "Thông báo");
                    LoadDanhSachPCGD();
                }
                else
                {
                    MessageBox.Show("Xóa không thành công");
                }
            }
            else
            {
                MessageBox.Show("Bạn chưa chọn gì để xóa, vui lòng chọn lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void GetPCGD(PhanCongGiangDay pc)
        {
            pc.MaGV = lvPCGD.SelectedItems[0].SubItems[0].Text;
            pc.MaMH = lvPCGD.SelectedItems[0].SubItems[1].Text;
            pc.HocKy = lvPCGD.SelectedItems[0].SubItems[2].Text;
            pc.NamHoc = lvPCGD.SelectedItems[0].SubItems[3].Text;
        }

        private void frmQuanLyPCGD_Load(object sender, EventArgs e)
        {
            LoadDanhSachPCGD();

        }

        private void LoadDanhSachPCGD()
        {
            List<PhanCongGiangDay> list = PhanCongGiangDay.All();
            lvPCGD.Items.Clear();
            foreach (PhanCongGiangDay pc in list)
            {
                ListViewItem item = lvPCGD.Items.Add(pc.MaGV.ToString());
                item.SubItems.Add(pc.MaMH.ToString());
                item.SubItems.Add(pc.HocKy.ToString());
                item.SubItems.Add(pc.NamHoc.ToString());
            }
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            FrmThemPCGD frm = new FrmThemPCGD();
            frm.ShowDialog();
            LoadDanhSachPCGD();
        }

       
    }
}
